<?php
require_once (APPLICATION_DIR."/application/model/Group_faq.php");

class Group_faq extends DataObjects_Group_faq
{
    function getAllQuestionInGroup($group_id)
    {
        $gf = $this->tableName();
        $faqObj = new Faq();
        $faq = $faqObj->tableName();
        $sql = "select $faq.faq_id as faq_id, $faq.faq_question as question_title,$faq.faq_answer as question_answer, $gf.group_order as question_order
                from $gf,$faq 
                where ($gf.group_id = $group_id) and ($faq.faq_id = $gf.faq_id)
                order by group_order";
        $this->_query($sql);
        return $this;
    }
    
//    function getListAllQuestionInGroup($group_id)
//    {
//        $gf = $this->tableName();
//        $faqObj = new Faq();
//        $faq = $faqObj->tableName();
//        $sql = "select $faq.faq_id as faq_id, $faq.faq_question as question_title, $faq.faq_answer as question_answer, $gf.group_order as question_order
//                from $gf,$faq 
//                where ($gf.group_id = $group_id) and ($faq.faq_id = $gf.faq_id)
//                order by group_order";
//        $this->_query($sql);
//        $this->fetchList();
//        return $this;
//    }
    
    function getOtherQuestion($group_id)
    {
        $gf = $this->tableName();
        $faqObj = new Faq();
        $faq = $faqObj->tableName();
        $sql = "select faq_id, faq_question, faq_order
                from $faq 
                where (faq_id not in 
                                        (select faq_id
                                         from $gf 
                                         where ($gf.group_id = $group_id)
                                         )
                       )
                group by faq_order";
        $this->_query($sql);
        return $this;
    }
    
    function getAllShowFaqGroupInfo()
    {
        $this->selectAdd();
        $this->selectAdd("*");
        $this->whereAdd();
        $this->whereAdd("faq_publish = 1");
        $this->orderBy("faq_order");
        $this->find();
        return $this;
    }
    
	function addQuestion($group_id,$faq_id,$order)
	{
	    $this->group_id  = $group_id;
	    $this->faq_id  = $faq_id;
	    $this->group_order = $order;
	    $this->insert();
	}
	
	function deleteQuestion($group_id,$faq_id,$order)
	{
	    $this->group_id  = $group_id;
	    $this->faq_id  = $faq_id;
	    $this->delete();
	}
	
	function updateQuestionOrder($group_id,$faq_id,$new_order)
	{
	    $this->group_id = $group_id;
	    $this->faq_id = $faq_id;
	    $this->group_order = $new_order;
	    $this->update();
	}
}

?>
